import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/material.dart';
/**
 * @Author wywinstonwy
 * @Date 2021/12/29 11:08 下午
 * @Description:
 */

class WyStack extends StatefulWidget {
  const WyStack({Key? key}) : super(key: key);

  @override
  _WyStackState createState() => _WyStackState();
}

class _WyStackState extends State<WyStack> {
  int _index =0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar('stack,positoned'),
      body: Column(
        children: [
          _buildView4(),
          Row(children: [
            ElevatedButton(onPressed: (){
              setState(() {
                _index=0;
              });
            }, child: Icon(Icons.fastfood)),
            ElevatedButton(onPressed: (){
              setState(() {
                _index=1;
              });
            }, child: Icon(Icons.cake)),
            ElevatedButton(onPressed: (){
              setState(() {
                _index=2;
              });
            }, child: Icon(Icons.local_cafe))
          ],)
        ],
      ),
    );
  }
  _buildView4(){
    return Container(
      height: 300,
      width: 300,
      color: Colors.amberAccent,
      child: Stack(
        children: <Widget>[
          Positioned(
            left: 10,
            right: 10,
            top: 10,
            bottom: 10,
            child: Container(color: Colors.red),
          ),
        ],
      ),
    );
  }
  _buildView3(){
    return IndexedStack(
      index: _index,
      children: [
        Center(
          child: Container(
            height: 300,
            width: 300,
            color: Colors.yellow,
            child: Icon(Icons.fastfood,color: Colors.blue,),
          ),
        ),

        Center(
          child: Container(
            height: 300,
            width: 300,
            color: Colors.red,
            child: Icon(Icons.cake,color: Colors.blue,),
          ),
        ),
        Center(
          child: Container(
            height: 300,
            width: 300,
            color: Colors.blueGrey,
            child: Icon(Icons.local_cafe,color: Colors.blue,),
          ),
        ),
      ],
    );
  }
  _buildView2(){
    return Stack(
      clipBehavior: Clip.none,
      children: <Widget>[
        Container(
          height: 200,
          width: 200,
          color: Colors.red,
        ),
        Positioned(
          left: 100,
          top: 100,
          height: 150,
          width: 150,
          child: Container(
            color: Colors.green,
          ),
        )
      ],
    );
  }
  _buildView1(){
    return Stack(
      fit: StackFit.loose,
      alignment: Alignment.center,
      children: <Widget>[
        Container(
          height: 200,
          width: 200,
          color: Colors.red,
        ),
        Container(
          height: 170,
          width: 170,
          color: Colors.blue,
        ),
        Container(
          height: 140,
          width: 140,
          color: Colors.yellow,
        ),
       Positioned(
         bottom: 0,
           right: 0,
           child:  ElevatedButton(onPressed: (){}, child: Text('这个视图按钮好')))
      ],
    );
  }
}
